<script>
import Comps from './Comps.js'
import { h } from 'vue'
import FomConfigs from './Comps.vue'
import ItemForComp from './ItemForComp.vue';

const isComponent = (c) => (typeof c === 'object' && (c.render || c.template));

export default {
    props: ['Configs', 'Values'],
    setup(props) {
        return function () {
            let GroupLength = 0;
            if (props.Configs && props.Values) {
                const Childs = [];
                for (let i = 0; i < props.Configs.length; i++) {
                    const element = props.Configs[i];
                    if (typeof element == 'string' && Comps[element]) {
                        Childs.push(h(Comps[element], { RuleValue: props.Values }));
                    } else if (typeof element == 'object' && element.type.indexOf(':') != -1) {
                        const Type = element.type.split(':');
                        if (Type[0] == 'Form') {
                            // 表单类型组件
                            Childs.push(h(ItemForComp, { FormType: Type[1], options: element, RuleValue: props.Values }));
                        } else {
                            // 其他类型组件
                        }
                    } if (typeof element == 'object' && element.type == 'Group') {
                        Childs.push(h(Comps['Group'], {
                            ...element.props,
                            isFirst: GroupLength == 0,
                            Configs: element,
                            Values: props.Values
                        }, () => {
                            return h(FomConfigs, {
                                Configs: element.children,
                                Values: props.Values
                            })
                        }));
                        GroupLength++;
                    } else if (typeof element == 'object' && Comps[element.type]) {
                        Childs.push(h(Comps[element.type]), element.props)
                    } else if (isComponent(element)) {
                        Childs.push(h(element, { Values: props.Values }))
                    }
                }
                return Childs
            } else {
                return undefined
            }
        }
    },
}
</script>
<style scoped lang="less"></style>